﻿<div ms-controller="ZDLIST">
    <!-- 添加按钮 -->
    <div class="btn-add">
        <button type="button" class="btn btn-info btn-lg" ms-click="init()" data-toggle="modal" data-target="#UpdateZD"><i class="iconfont icon-jiahao ft12 mr5"></i>添加类型</button>
    </div>
    <!-- 按条件选择 -->
    <div class="tab-filter-type">
        <!-- 搜索 -->
        <div class="oh">
            <div class="input-group ml15" style="width:295px;">
                <input type="search" class="form-control" ms-duplex="search.searchcontent" placeholder="搜索名称">
                <span class="input-group-addon" ms-click="GetLIST()">搜索</span>
            </div>
        </div>
    </div>
    <!-- 表格 -->
    <div class="default-tab ft14 pt20">
        <table class="table table-striped table-responsive table-hover">
            <thead>
                <tr>
                    <th width="2%"></th>
                    <th width="5%">序号</th>
                    <th width="30%">名称</th>
                    <th width="53%">描述</th>
                    <th width="10%">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-item="ZiDianDataList">
                    <td></td>
                    <td>{{$index+1}}</td>
                    <td>{{item.TypeName}}</td>
                    <td>{{item.Remark1}}</td>
                    <td>
                        <a class="cz-btn ft18 bj-color tip" data-toggle="modal" data-target="#UpdateZD" ms-click="saveitem(item)" title="编辑">
                            <i class="iconfont icon-bianji"></i>
                        </a>
                        <a class="cz-btn ft18 sc-color tip" title="删除" ms-click="DelType(item)">
                            <i class="iconfont icon-shanchu"></i>
                        </a>
                    </td>
                </tr>
            </tbody>
            <tfoot>
                <tr ms-if="isnull"><td class="tc"></td><td class="tc"></td><td>暂无数据</td></tr>
            </tfoot>
        </table>
    </div>
    <div class="modal fade" id="UpdateZD" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">分类管理</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label"><span class="Required " style="color:red">*</span>分类名称</label>
                            <input type="text" class="form-control szhl_require" style="width: 200px" placeholder="请输入分类" ms-duplex="zditem.TypeName" />
                        </div>
                        <div class="form-group">
                            <label class="col-xs-4 control-label">分类描述</label>
                            <textarea type="text" rows="3" class="form-control" style="width: 200px" placeholder="分类描述" ms-duplex="zditem.Remark1" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="SaveZiDian()">确&nbsp;&nbsp;认</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    var tempindex = avalon.define({
        $id: "ZDLIST",
        ClassID: "",
        ZiDianDataList: [],
        ZiDianData: { Class: "", TypeName: "", Remark1: "" },
        zditem: { Class: "", TypeName: "", Remark1: "" },
        InitWigetData: function (arr) {
            tempindex.ClassID = arr;
            tempindex.ZiDianData.Class = tempindex.ClassID;
            tempindex.GetLIST();
        },
        init: function () {
            tempindex.zditem = { Class: tempindex.ClassID, TypeName: "", Remark1: "" }
        },
        GetLIST: function () {
            $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETZIDIANLIST', { P1: tempindex.ClassID, P2: model.search.searchcontent }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    tempindex.ZiDianDataList = resultData.Result;
                    if (tempindex.ZiDianDataList.size() == 0) { model.isnull = true; } else { model.isnull = false; }
                }
            })
        }, DelType: function (item, event) {
            if (event) {
                event.stopPropagation();
            }
            ComFunJS.winconfirm("确认要删除“" + item.TypeName + "”吗？", function () {
                $.post("/API/VIEWAPI.ashx?ACTION=XTGL_DELTYPEBYID", { P1: item.ID }, function (jsonresult) {
                    if ($.trim(jsonresult.ErrorMsg) == "") {
                        tempindex.ZiDianDataList.remove(item);
                        if (tempindex.ZiDianDataList.size() == 0) { model.isnull = true; }
                        ComFunJS.winsuccess("操作成功");
                    }
                });
            }, function () { })
        }, SaveZiDian: function () {
            if (!tempindex.zditem.TypeName) {
                ComFunJS.winwarning("请输入分类名称");
                return;
            }
            var bl = true;
            if (tempindex.zditem.ID) { bl = false; }
            else { tempindex.zditem.Class = tempindex.ClassID; }
            $.post("/API/VIEWAPI.ashx?ACTION=XTGL_SAVETYPEMODEL", { P1: JSON.stringify(tempindex.zditem.$model) }, function (jsonresult) {
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    if (!bl) {
                        tempindex.ZiDianDataList.forEach(function (zditem) {
                            if (tempindex.zditem.ID == zditem.ID) {
                                zditem.TypeName = tempindex.zditem.TypeName;
                                zditem.Remark1 = tempindex.zditem.Remark1;
                            }
                        })
                    }
                    else {
                        tempindex.ZiDianDataList.push(jsonresult.Result);
                        model.isnull = false;
                    }
                    tempindex.ZiDianData = { Class: tempindex.ClassID, TypeName: "", Remark1: "" };
                    tempindex.zditem = { Class: tempindex.ClassID, TypeName: "", Remark1: "" };
                    ComFunJS.winsuccess("操作成功");
                    $('#UpdateZD').modal('hide');
                }
            });
        },
        saveitem: function (item) {
            tempindex.ZiDianData = item;
            //tempindex.zditem.TypeName = item.TypeName;
            //tempindex.zditem.Remark1 = item.Remark1;
            tempindex.zditem = tempindex.ZiDianData;
        }
    })
    //# sourceURLZDLIST.js;
</script>
